import java.util.LinkedList;


class P622_39643 {

	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		
		for (int k = 0; k < cases; k++) {
			String line = readLn();
			if (!isOk(line)) {
				System.out.println("ERROR");
			} else {
				
				LinkedList<String> tokens = parse(line);
//				System.out.println(tokens);
//				System.out.println(tokens.size());
				
				try {
					System.out.println(evaluate(tokens));
				} catch (Exception e) {
					System.out.println("ERROR");
				}
				
			}
			
		}
		
	}
	
	private static int evaluate(LinkedList<String> tokens) {
//		System.out.println("evaluate " + tokens);
		int value = 0;
		
		value = evaluateExpression(tokens);
		
		if (tokens.size() != 0) throw new RuntimeException();
		
		return value;
	}

	private static int evaluateExpression(LinkedList<String> tokens) {
//		System.out.println("evaluateExpression " + tokens);
		
		int value = evaluateComponent(tokens);
		
		if (!tokens.isEmpty()) {
			if ("+".equals(tokens.getFirst())) {
				tokens.removeFirst();
				value += evaluateExpression(tokens);
			}
				
		}
		
//		System.out.println("returning evaluateExpression  " + tokens);
		return value;
	}

	private static int evaluateComponent(LinkedList<String> tokens) {
//		System.out.println("evaluateComponent " + tokens);
		int value = evaluateFactor(tokens);
		
		if (!tokens.isEmpty()) {
			
			if ("*".equals(tokens.getFirst())) {
				tokens.removeFirst();
				value *= evaluateComponent(tokens);
			}
		}
//		System.out.println("returning evaluateComponent " + tokens);
		return value;
	}

	private static int evaluateFactor(LinkedList<String> tokens) {
//		System.out.println("evaluateFactor " + tokens);
		
		String e = tokens.removeFirst();
		try {
			return Integer.parseInt(e);
		} catch(NumberFormatException ex) {
			
			if ("(".equals(e)) {
				int value = evaluateExpression(tokens);
				e = tokens.removeFirst();
				if (")".equals(e)) {
					return value;
				} else throw new RuntimeException();
			} else throw new RuntimeException();
			
		}
	}

	private static boolean isOk(String line) {
		for (int k = 0; k < line.length(); k++) {
			char c = line.charAt(k);
			if (!(isDigit(c) || c == '(' || c == ')' || c == '*' || c == '+')) 
				return false;
		}
		
		return true;
	}

	static LinkedList<String> parse(String line) {
		LinkedList<String> result = new LinkedList<String>();
		
		for (int k = 0; k < line.length(); k++) {
			char c = line.charAt(k);
			
			// read digit
			if (isDigit(c)) {
				StringBuilder sb = new StringBuilder();
				int j = k;
				k = line.length() - 1;
				for (;  j < line.length(); j++) {
					c = line.charAt(j);
					if (isDigit(c)) {
						sb.append(line.charAt(j));
					} else {
						k = j - 1;
						break;
					}
				}
				result.add(sb.toString());			
			}
			
			c = line.charAt(k);
			
			if (c == '(' || c == ')' || c == '*' || c == '+') 
				result.add(Character.toString(c));

		}
		
		
		return result;
	}

	private static boolean isDigit(char c) {
//		System.out.println(c + " -> " + (c >= '0' && c <= '9'));
		return (c >= '0' && c <= '9');
	}
	
	  static String readLn() {
	        String newLine = System.getProperty("line.separator");
	        StringBuffer buffer = new StringBuffer();
	        int car = -1;
	        try {
	            car = System.in.read();
	            while ((car > 0) && (car != newLine.charAt(0))) {
	                if (car != ' ')
	                	buffer.append((char) car);
	                car = System.in.read();
	            }
	            if (car == newLine.charAt(0))
	                System.in.skip(newLine.length() - 1);
	        } catch (java.io.IOException e) {
	            return (null);
	        }
	        if ((car < 0) && (buffer.length() == 0))
	            return (null);
	        return (buffer.toString()).trim();
	    }
}
